.TH std::strlen 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::strlen \- std::strlen

.SH Synopsis
   Defined in header <cstring>
   std::size_t strlen( const char* str );

   Returns the length of the given byte string, that is, the number of characters in a
   character array whose first element is pointed to by str up to and not including the
   first null character. The behavior is undefined if there is no null character in the
   character array pointed to by str.

.SH Parameters

   str - pointer to the null-terminated byte string to be examined

.SH Return value

   The length of the null-terminated string str.

.SH Possible implementation

   std::size_t strlen(const char* start)
   {
       // NB: start is not checked for nullptr!
       const char* end = start;
       while (*end != '\\0')
           ++end;
       return end - start;
   }

.SH Example


// Run this code

 #include <cstring>
 #include <iostream>

 int main()
 {
     const char str[] = "dog cat\\0mouse";

     std::cout << "without null character: " << std::strlen(str) << '\\n'
               << "with null character: " << sizeof str << '\\n';
 }

.SH Output:

 without null character: 7
 with null character: 14

.SH See also

   wcslen returns the length of a wide string
          \fI(function)\fP
   mblen  returns the number of bytes in the next multibyte character
          \fI(function)\fP
   C documentation for
   strlen
